
import datetime
from models.base import *


class LoginHistory(TimestampMixin, Model):
    account_id = fields.CharField(max_length=50, description="account id")
    enterprise_id = fields.CharField(max_length=50, description="enterprise id")
    name = fields.CharField(max_length=50, description="name")
    account = fields.CharField(max_length=50, description="login account")
    ip = fields.CharField(max_length=16, description="login ip")


    class Meta:
        abstract = False
        table = 'a_login_history'
        table_description = '登录记录'

    async def list_to_dict(self):
        request_dict = {f: getattr(self, f) for f in self._meta.fields}
        request_dict['create_ts'] = datetime.datetime.strftime(request_dict['create_ts'], '%Y-%m-%d')
        request_dict['update_ts'] = datetime.datetime.strftime(request_dict['update_ts'], '%Y-%m-%d')
        return request_dict
